package util

import (
	"net"
	"net/http"
	"strings"
)

func GetRemoteIP(r *http.Request) string {
	if s := r.Header.Get("X-Forwarded-For"); s != "" {
		ss := strings.Split(s, ",")
		return strings.TrimSpace(ss[0])
	}
	ip, _, _ := net.SplitHostPort(r.RemoteAddr)
	return ip
}
